package api

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"user-center/src/model/request"
	"user-center/src/service"
)

// GroupChatAdd
// @Tags        group
// @Summary     群聊发消息
// @Description  群聊发消息
// @Param GroupChatAdd body request.GroupMessageRequest true "GroupChatAdd"
// @Router /group/chat/sendMessage [post]
func GroupChatAdd(ctx *gin.Context) {
	req := &request.GroupMessageRequest{}
	err := parsePostJsonRequest(ctx, req)
	if err != nil {
		return
	}
	//处理请求
	res := service.GroupChatAdd(ctx, req)
	ctx.JSON(http.StatusOK, res)
}

// GroupChatList GroupLists GET
// @Tags        group
// @Summary     所有群聊最新消息
// @Description  所有群聊最新消息
// @Param pageNum query int true "页数"
// @Param pageSize query int true "每页大小"
// @Router /group/chat/list [get]
func GroupChatList(ctx *gin.Context) {
	pageNum, pageSize := pageNumAndSize(ctx)
	currentUser := service.GetUserCurrentInfo(ctx)
	ctx.JSON(http.StatusOK, service.ListGroups(ctx, pageNum, pageSize, currentUser))
}

// GroupChatHistory  GET
// @Tags        group
// @Summary     群聊历史消息
// @Description   群聊历史消息
// @Param pageNum query int true "页数"
// @Param pageSize query int true "每页大小"
// @Router /group/chat/history [get]
func GroupChatHistory(ctx *gin.Context) {
	GroupChatId := ctx.Query("groupId")
	ctx.JSON(http.StatusOK, service.ListHistoryByGroup(ctx, GroupChatId))
}

// GroupMemberList  GET
// @Tags        group
// @Summary     群成员
// @Description   群成员
// @Param groupId query string true "页数"
// @Router /group/member/list [get]
func GroupMemberList(ctx *gin.Context) {
	GroupChatId := ctx.Query("groupId")
	ctx.JSON(http.StatusOK, service.ListMemberByGroup(ctx, GroupChatId))
}
